<template>
    <div>
<!--面包屑区域-->
    <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item><a href="/">职位管理</a></el-breadcrumb-item>
        <el-breadcrumb-item><a href="/">查询职位</a></el-breadcrumb-item>
      </el-breadcrumb>
      <!-- 搜索区域-->
   <el-form :inline="true" :model="queryparams" class="demo-form-inline" size="small" label-width="80px">
    <el-row>
        <el-col :span="6">
             <el-form-item label="职位名称:">
            <el-input v-model="queryparams.name" placeholder="请输入职位"></el-input>
            </el-form-item>
        </el-col>
    <el-form-item>
      <el-button type="primary" icon="el-icon-search" id="query" @click="queryJob">搜索</el-button>
    </el-form-item>
    </el-row>

  </el-form>
 <el-table
    ref="multipleTable"
    :data="JobList"
    tooltip-effect="dark"
    style="width: 100%"
    @selection-change="handleSelectionChange">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    
    <el-table-column
      prop="name"
      label="职位名称"
      width="400"
      align="center">
    </el-table-column>

     <el-table-column
      prop="remark"
      label="详细信息"
      width="400"
      align="center">
    </el-table-column>
    
     <el-table-column
      label="操作"
      show-overflow-tooltip=""
      align="center">
    
      <template slot-scope="scope">  
        <el-button type="primary" icon="el-icon-edit" circle @click="editJob(scope.row.id)" ></el-button>
        <el-button type="danger" icon="el-icon-delete" circle @click="deleteJob(scope.row.id)" ></el-button>
      </template>


    </el-table-column>
  </el-table>
  <div style="margin-top: 20px">
    <el-button @click="toggleSelection()">取消选择</el-button>
  </div>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryparams.currentPage"
        :page-sizes="[5, 10, 20]"
        :page-size="queryparams.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>

    </div> 
</template>
<script>

  export default {
    name: 'JobShow',
    data() {
      return {
        tableData: [],
        multipleSelection: [],
        total:0,//总条数
      queryparams :{
        name:"",
        remark:"",
        currentPage:1,
        pagesize:5,
      },
      JobList:[]
      ,
      }
    },
    mounted(){
     this.getJobList();
    },

    methods: {
      onSubmit() {
      },

      getJobList(){
        console.log(this.queryparams)
        this.$http.post("/job/findPage",this.queryparams).then(resp =>{
                console.log(resp)
                if(resp.data.flag){
                this.JobList=resp.data.data.rows
                this.total = resp.data.data.total
                console.log(this.JobList)
                  console.log("查询职位列表成功")
                }else{
                  console.log("查询职位列表失败")
                }
        })
      },
      queryJob(){
        this.getJobList()
      },
      handleSizeChange(val) {
        this.queryparams.employeeName=""
        this.queryparams.pagesize=val;
        this.queryparams.currentPage=1;
          this.getJobList()
      },
      handleCurrentChange(val) {
        this.queryparams.employeeName=""
        this.queryparams.currentPage=val;
          this.getJobList()
    
      },
       getEmployeeIds() {
      return this.multipleSelection.map(employee => employee.id);
    },

       deleteJob(id) {
        this.$confirm('此操作将永久删除这些职位, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http.post(`/job/delete/${id}`,{
        headers: {
        'Content-Type': 'application/json'
    }
      }).then(resp =>{
            if(resp.data.flag){
              this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.queryparams.currentPage=1
          this.getJobList()
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
      },

      
       toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },

      handleSelectionChange(val) {
        this.multipleSelection = val;
      },

      editJob(id){
             this.$router.push({path:"/jobedit",query:{'id':id}})
      }

    }
  }
</script>

<style scoped>
 .el-form-item .el-input{
   margin-top: 10px;
 }
 .slt{
   margin-top: 10px !important;
 }
.el-form-item__label{
   padding: 13px 12px 0px 0px  !important;
   color:red !important
 }
 .el-form--inline .el-form-item{
  display: flex;
  align-items: flex-end;
  flex-direction: row;
 }
#query{
    padding: 13px 31px;
    font-size: 12px;
    border-radius: 8px;
 }
#delete{
    padding: 13px 31px;
    font-size: 12px;
    border-radius: 8px;
 }
</style>
